package top.huntwolf.admin.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import top.huntwolf.admin.component.URLMessageCenter;
import top.huntwolf.admin.interceptor.LoginInterceptor;
import top.huntwolf.admin.service.UserService;

import java.util.List;
import java.util.Map;

@Configuration
public class LoginConfig implements WebMvcConfigurer {

    //不配置这个不能在拦截器注入bean
    @Bean
    public LoginInterceptor loginInterceptor(){
        return new LoginInterceptor();
    }

    @Autowired
    URLMessageCenter urlMessageCenter;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<Map<String, String>> urls = urlMessageCenter.getURL();
        for (Map map:urls){
            registry.addInterceptor(loginInterceptor())
                    .addPathPatterns((String) map.get("url"));//所有接口均配置拦截器
        }

    }





}
